const jwt = require("jsonwebtoken");
module.exports = function(){
  return (req, res, next)=>{
    const token = req.query.token || req.body.token;
    // 解析token
    jwt.verify(token, "千锋H5", (err, data)=>{
      if(err){
        // 失败：send(失效)
        res.send({state: -1, msg:"登录失效"});
      }else{
        // 成功：next()
        req.userMsg = data;
        next();
      }
    });
  }
}